<?php

$_this =& $this;

/* @var $_this View */
/* @var $form FormHelper */
/* @var $editForm EditFormHelper */
/* @var $html HtmlHelper */
/* @var $ehtml EHtmlHelper */
/* @var $javascript JavascriptHelper */
/* @var $jqax JqaxHelper */
/* @var $filterBlock FilterBlock */

$this_user = Auth::o()->is('client_admin') && (Auth::o()->realId() == $this->data[$modelName][$PKName]);

?><?=$editForm->create($modelName, array('url'=>("/{$url_part}/".($mode == 'create' ? 'new' : $this->data[$modelName][$PKName]).'/'), 'allowInput' => $this->data[$modelName]['__allows']['update']));?><?php

	?><?=$editForm->startSet();?><?php
        if ($mode !== 'create') {
        	?><?=$editForm->datetimeView(__d($po_domain, 'created_field', true), $this->data[$modelName]['created']);?><?php
        }
		?><?=$editForm->select("client_id", __d($po_domain, 'client_id', true), $clients_list, null, array('allowInput'=>!$this_user), '');?><?php
		?><?=$editForm->select("status", __d($po_domain, 'status', true), $statuses_list, null, array('allowInput'=>!$this_user), false);?><?php
	?><?=$editForm->endSet();?><?php

	?><?=$editForm->startSet();?><?php
		?><?=$editForm->text("username", __d($po_domain, 'username', true), array('required' => true, 'vertical' => false, 'size'=>30));?><?php
		?><?=$editForm->text('name', __d($po_domain, 'name', true), array('required' => true, 'vertical' => false, /*'size'=>30, */'maxlength'=>'255'));?><?php
		if( Auth::o()->is('admin') && !empty($this->data[$modelName]['old_password'])) {
		    ?><?=$editForm->textView( __d($po_domain, 'Current password', true), $this->data[$modelName]['old_password']);?><?
        }
        if ($this->data[$modelName]['__allows']['update']) {
    		?><?=$editForm->text("password", __d($po_domain, 'New password', true), array('required' => true, 'vertical' => false));?><?php
    		/*?><?=$editForm->field("confirm_password", __d($po_domain, 'password_confirm', true), $form->password('confirm_password', array('size'=>30)), array('required' => true, 'vertical' => false));?><?php*/
        }
		?><?=$editForm->textarea("address", __d($po_domain, 'address', true), array( 'vertical' => false));?><?php
		?><?=$editForm->text("phone", __d($po_domain, 'phone', true), array( 'vertical' => false));?><?php
		?><?=$editForm->text("cell_phone", __d($po_domain, 'cell_phone', true), array( 'vertical' => false));?><?php
		?><?=$editForm->text("email", __d($po_domain, 'email', true), array('required' => true, 'vertical' => false, 'size'=>30, 'maxlength'=>'100'));?><?php

	?><?=$editForm->endSet();?><?php

	?><?=$editForm->startSet(); $checkboxes = '';?><?php
		?><?/*=$checkbox->checkboxMultiple('permissions', __d($po_domain, 'permissions', true), $permissions_list);*/?><?php
		  ?><?/*=$checkbox->checkboxMultiple('permissions', $permissions_list, null, null, null, true);*/
		  foreach ($permissions_list as $id=>$label) {
                $checkboxes .= '<input type="checkbox" id="'.$modelName.'Permissions'.$id.'" name="data['.$modelName.'][permissions][]"';
                $checkboxes .= ' value="'.$id.'"';
                in_array($id, $this->data[$modelName]["permissions"]) ? $checkboxes .= ' checked="checked"' : false;
                $checkboxes .= ' />';
                $checkboxes .= '<label for="'.$modelName.'Permissions'.$id.'">'.$label.'</label><br />';
          }
    ?><?=$editForm->cell($checkboxes);?><?php
	?><?=$editForm->endSet();?><?php

	$buttonsHTML = '';
	$buttonsHTML .= (strlen($buttonsHTML) ? ' ' : '').$editForm->back("/{$url_part}/");
	if ($this->data[$modelName]['__allows']['update']) {
	   $buttonsHTML .= (strlen($buttonsHTML) ? ' ' : '').$editForm->submit(__d(null, ($mode == 'create' ? 'create' : 'save'), true), array());
	}
	if (strlen($buttonsHTML)) {
    	?><?=$editForm->cell($buttonsHTML);?><?php
	}

?><?=$editForm->end();?><?php

?>
